package com.century.sjt.EMChat.activity;

import android.Manifest;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.century.sjt.EMChat.db.TranslateDao;
import com.century.sjt.EMChat.domain.EaseUser;
import com.century.sjt.EMChat.fragment.ChatFragment;
import com.century.sjt.EMChat.fragment.EaseChatFragment;
import com.century.sjt.EMChat.utils.EaseUserUtils;
import com.century.sjt.R;
import com.century.sjt.SjtHelper;
import com.century.sjt.SjtModel;
import com.century.sjt.activity.BaseActivity;
import com.century.sjt.activity.Pay.CommodityListActivity;
import com.century.sjt.activity.Pay.MerchantItemActivity;
import com.century.sjt.activity.wallet.TranslateActivity;
import com.century.sjt.activity.wallet.TranslateShopActivity;
import com.century.sjt.entity.ActionItem;
import com.century.sjt.entity.Merchant;
import com.century.sjt.util.Constant;
import com.century.sjt.util.TipUtil;
import com.century.sjt.widget.TitleBar.ChatTitleBar;
import com.century.sjt.window.MenuPopup;
import com.easemob.chat.EMChatManager;

import org.json.JSONObject;
import org.json.JSONTokener;

import java.util.HashMap;
import java.util.Map;


/**
 * 聊天页面，需要fragment的使用
 */

public class ChatActivity extends BaseActivity {
    public static ChatActivity activityInstance;
    private EaseChatFragment chatFragment;
    private ChatTitleBar titleBar;
    String toChatUsername;
    private EaseUser toChatUser = null;
    // private PopupMenu popupMenu;
    // private Menu menu;

    private MenuPopup mMenuPopup;
    SharedPreferences mainSharedPreferences;
    private boolean isMsgSpeaker = true;
    private boolean isOpenBaiduTranslate = false;
    private String isShop, isMerchant,isTrans;
    private int chatType;
    protected SjtModel settingsModel;
    final private int REQUEST_CODE_ASK_PERMISSIONS = 123;

    private void insertDummyContactWrapper() {
        int hasCameraContactsPermission = ContextCompat.checkSelfPermission(ChatActivity.this,
                Manifest.permission.CAMERA);//拍照权限
        int hasWriteContactsPermission = ContextCompat.checkSelfPermission(ChatActivity.this,
                Manifest.permission.WRITE_EXTERNAL_STORAGE);//存储权限
        int hasPhoneContactsPermission = ContextCompat.checkSelfPermission(ChatActivity.this,
                Manifest.permission.READ_PHONE_STATE);//电话权限
        int hasReadContactsPermission = ContextCompat.checkSelfPermission(ChatActivity.this,
                Manifest.permission.READ_CONTACTS);//通讯录权限
        int hasRECORDContactsPermission = ContextCompat.checkSelfPermission(ChatActivity.this,
                Manifest.permission.RECORD_AUDIO);//麦克风权限
        int hasLOCATIONContactsPermission = ContextCompat.checkSelfPermission(ChatActivity.this,
                Manifest.permission.ACCESS_FINE_LOCATION);//地理位置权限
        if (Build.VERSION.SDK_INT >= 23) {
            if (hasCameraContactsPermission != PackageManager.PERMISSION_GRANTED || hasRECORDContactsPermission != PackageManager.PERMISSION_GRANTED
                    || hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED || hasLOCATIONContactsPermission != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(ChatActivity.this,
                        new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO, Manifest.permission.WRITE_EXTERNAL_STORAGE
                                , Manifest.permission.ACCESS_FINE_LOCATION},
                        REQUEST_CODE_ASK_PERMISSIONS);
                return;
            }
        }


    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (requestCode == REQUEST_CODE_ASK_PERMISSIONS) {
            if (permissions[0].equals(Manifest.permission.CAMERA)
                    && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                //用户同意使用write

            } else {
                //用户不同意，自行处理即可
                finish();
            }
        }
    }

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_chat);
        activityInstance = this;
        //聊天人或群id
        toChatUsername = getIntent().getExtras().getString("userId");
        toChatUser = SjtHelper.getInstance().getUser(toChatUsername);
//        Log.e("user",toChatUsername);
        //可以直接new EaseChatFratFragment使用
        chatFragment = new ChatFragment();
        //传入参数
        chatFragment.setArguments(getIntent().getExtras());
        getSupportFragmentManager().beginTransaction().add(R.id.container, chatFragment).commit();
        if (SjtHelper.getInstance().getContactList().get(toChatUsername) == null) {
            //询问是否取消
            AlertDialog.Builder builder = new AlertDialog.Builder(ChatActivity.this);
            builder.setTitle(getResources().getString(R.string.text_prompt));
            builder.setMessage(getResources().getString(R.string.error_isno_tolist_friends));
            builder.setPositiveButton(getResources().getString(R.string.btn_yes), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
//                    EMChatManager.getInstance().clearConversation(toChatUsername);
                    TranslateDao translateDao = new TranslateDao(ChatActivity.this);
                    translateDao.deleteOneTranslateDao(toChatUsername);//清空翻译记录
                    EMChatManager.getInstance().clearConversation(toChatUsername);
                    chatFragment.getMessageList().refresh();
                    dialog.dismiss();
                    finish();
                }
            });
            builder.setCancelable(false);
            builder.create().show();
        }else {
            insertDummyContactWrapper();
            initView();
            initEvent();
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        activityInstance = null;
    }

    @Override
    protected void initView() {
        titleBar = (ChatTitleBar) findViewById(R.id.title_bar);
        titleBar.setTitle(toChatUser.getNick());
        titleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        titleBar.setRightIcon2Resourc(getResources().getString(R.string.icon_more));
        titleBar.setRightIcon1Resourc(getResources().getString(R.string.icon_voice));
    }

    @Override
    protected void initEvent() {
        settingsModel = SjtHelper.getInstance().getModel();
        mainSharedPreferences = getSharedPreferences(com.century.sjt.util.Constant.TAG, Activity.MODE_PRIVATE);
        isShop = mainSharedPreferences.getString("isShop", "");
        isMerchant = mainSharedPreferences.getString("isMerchant", "");
        isTrans = mainSharedPreferences.getString("isTrans","");
        titleBar.setTitle(EaseUserUtils.getUserInfo(toChatUsername).getNick());
        if (settingsModel.getSettingMsgSpeaker()) {
            titleBar.setRightIcon1Resourc(getResources().getString(R.string.icon_earpiece));
            isMsgSpeaker=true;
        } else {
            titleBar.setRightIcon1Resourc(getResources().getString(R.string.icon_earpiece2));
            isMsgSpeaker=false;
        }
        titleBar.setRightIcon1ClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (isMsgSpeaker){
                    titleBar.setRightIcon1Resourc(getResources().getString(R.string.icon_earpiece2));
                    isMsgSpeaker=false;
                    settingsModel.setSettingMsgSpeaker(false);
                    TipUtil.showToast(getResources().getString(R.string.error_earpiece2),ChatActivity.this, 1);
                }else {
                    titleBar.setRightIcon1Resourc(getResources().getString(R.string.icon_earpiece));
                    isMsgSpeaker=true;
                    settingsModel.setSettingMsgSpeaker(true);
                    TipUtil.showToast(getResources().getString(R.string.error_earpiece),ChatActivity.this, 1);
                }
            }
        });
        mMenuPopup = new MenuPopup(this, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        时间
//        mMenuPopup.addAction(new ActionItem(this, getResources().getString(R.string.text_time), getResources().getString(R.string.icon_time)));
//        听筒
//        mMenuPopup.addAction(new ActionItem(this, getResources().getString(R.string.text_receiver), getResources().getString(R.string.icon_earpiece)));
        if ("1".equals(toChatUser.getIsShop())){
            mMenuPopup.addAction(new ActionItem(this, getResources().getString(R.string.text_pay), getResources().getString(R.string.icon_pay)));
            mMenuPopup.addAction(new ActionItem(this, getResources().getString(R.string.text_goto_shop), getResources().getString(R.string.icon_store)));
        }
        if (settingsModel.getSettingBaiTranslate()) {
            isOpenBaiduTranslate = true;
            mMenuPopup.addAction(new ActionItem(this, getResources().getString(R.string.text_close_translate), getResources().getString(R.string.icon_translation)));

        } else {
            isOpenBaiduTranslate = false;
            mMenuPopup.addAction(new ActionItem(this, getResources().getString(R.string.text_open_translate), getResources().getString(R.string.icon_translation)));

        }
        mMenuPopup.addAction(new ActionItem(this, getResources().getString(R.string.text_clear_message), getResources().getString(R.string.icon_aTrash)));

        //这里处理时间、听筒、支付、翻译点击事件
        mMenuPopup.setItemOnClickListener(new MenuPopup.OnItemOnClickListener() {
            @Override
            public void onItemClick(ActionItem item, int position) {
                if ("1".equals(toChatUser.getIsShop())){
                    switch (position) {
                        //支付
                        case 0:
                            shopDetail(toChatUser.getShopId(),"0");
                            break;
                        case 1:
                            shopDetail(toChatUser.getShopId(),"1");
                            break;
                        //翻译
                        case 2:
                            if ("1".equals(isTrans)){//是否开通翻译 0 否 1 是
                                if (isOpenBaiduTranslate){
                                    mMenuPopup.setTitle(2,getResources().getString(R.string.text_open_translate));
                                    settingsModel.setSettingBaiTranslate(false);
                                    isOpenBaiduTranslate = false;
                                    isOpenBaiduTranslate("1");
                                }else {
                                    mMenuPopup.setTitle(2,getResources().getString(R.string.text_close_translate));
                                    settingsModel.setSettingBaiTranslate(true);
                                    isOpenBaiduTranslate = true;
                                    isOpenBaiduTranslate("0");
                                }
                            }else {
                                //询问是否开通翻译
                                transInfoDetail("1");
                            }

                            break;
                        case 3:
                            //询问是否取消

                            AlertDialog.Builder builder = new AlertDialog.Builder(ChatActivity.this);
                            builder.setMessage(getResources().getString(R.string.error_isno_clear_message));
                            builder.setPositiveButton(getResources().getString(R.string.btn_yes), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    TranslateDao translateDao = new TranslateDao(ChatActivity.this);
                                    translateDao.deleteOneTranslateDao(toChatUsername);//清空翻译记录
                                    EMChatManager.getInstance().clearConversation(toChatUsername);
                                    chatFragment.getMessageList().refresh();
                                }
                            });
                            builder.setNegativeButton(getResources().getString(R.string.btn_no), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                            builder.setCancelable(false);
                            builder.create().show();

                            break;
                    }
                }else {
                    switch (position) {
                        //翻译
                        case 0:
                            if ("1".equals(isTrans)){
                                if (isOpenBaiduTranslate){
                                    mMenuPopup.setTitle(0,getResources().getString(R.string.text_open_translate));
                                    isOpenBaiduTranslate("1");
                                    settingsModel.setSettingBaiTranslate(false);
                                    isOpenBaiduTranslate = false;
                                }else {
                                    mMenuPopup.setTitle(0,getResources().getString(R.string.text_close_translate));
                                    settingsModel.setSettingBaiTranslate(true);
                                    isOpenBaiduTranslate = true;
                                    isOpenBaiduTranslate("0");
                                }
                            }else {
                                transInfoDetail("2");

                            }

                            break;
                        //清空聊天记录
                        case 1:
                            // 清空会话
                            //询问是否取消
                            AlertDialog.Builder builder = new AlertDialog.Builder(ChatActivity.this);
                            builder.setMessage(getResources().getString(R.string.error_isno_clear_message));
                            builder.setPositiveButton(getResources().getString(R.string.btn_yes), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    TranslateDao translateDao = new TranslateDao(ChatActivity.this);
                                    translateDao.deleteOneTranslateDao(toChatUsername);//清空翻译记录
                                    EMChatManager.getInstance().clearConversation(toChatUsername);
                                    chatFragment.getMessageList().refresh();
                                                 }
                            });
                            builder.setNegativeButton(getResources().getString(R.string.btn_no), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                            builder.setCancelable(false);
                            builder.create().show();

                            break;
                    }
                }

            }
        });


        titleBar.setRightIcon2ClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //  popupMenu.show();
                mMenuPopup.show(v);
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onNewIntent(Intent intent) {
        // 点击notification bar进入聊天页面，保证只有一个聊天页面
        String username = intent.getStringExtra("userId");
        if (toChatUsername.equals(username))
            super.onNewIntent(intent);
        else {
            finish();
            startActivity(intent);
        }

    }

    @Override
    public void onBackPressed() {
        chatFragment.onBackPressed();
    }

    public String getToChatUsername() {
        return toChatUsername;
    }
    //商家支付
    private void shopDetail(final String shopId,final String type) {
        TipUtil.openProgressDialog(com.century.sjt.util.Constant.APPLICATION_NAME, getResources().getString(R.string.error_please_waitting), ChatActivity.this);
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.ShopDetail, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TipUtil.closeProgressDialog();
                    TipUtil.log("接口返回成功", response.toString(), 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("200")) {//成功
                        JSONObject aData = res.getJSONObject("data");
                        Merchant merchant = new Merchant();
                        merchant.setShopId(aData.getString("shopId"));
                        merchant.setShopName(aData.getString("shopName"));
//                            Log.e("name",aData.getString("shopName"));
                        merchant.setLogo(aData.getString("logo"));
                        merchant.setDiscount(aData.getString("discount"));
                        merchant.setAddress(aData.getString("address"));
                        merchant.setTelephone(aData.getString("telephone"));
                        merchant.setTelephoneOne(aData.getString("telephoneOne"));
                        merchant.setMobile(aData.getString("mobile"));
                        merchant.setDesc(aData.getString("desc"));
                        merchant.setCity(aData.getString("city"));
                        merchant.setImage(aData.getString("image"));
                        merchant.setUserId(aData.getString("userId"));
                        merchant.setLastTopic(aData.getString("lastTopic"));
                        merchant.setNewGoods(aData.getString("newGoods"));
                        merchant.setLevel(aData.getInt("level"));
                        merchant.setDetailsUrl(aData.getString("detailsUrl"));
                        merchant.setNationalFlag(aData.getString("nationalFlag"));
                        merchant.setCurrencyCode(aData.getString("currencyCode"));
                        merchant.setCurrency(aData.getString("currency"));
                        merchant.setExRate(aData.getString("exRate"));
                        merchant.setDiscountDeduct(aData.getString("discountDeduct"));
                        merchant.setVipDiscountDeduct(aData.getString("vipDiscountDeduct"));
                        if ("0".equals(type)){
                            Intent intent = new Intent();
                            intent.setClass(ChatActivity.this, MerchantItemActivity.class);
                            Bundle mBundle = new Bundle();
                            mBundle.putSerializable("Merchant", merchant);
                            intent.putExtras(mBundle);
                            intent.putExtra("payType","2");
                            startActivity(intent);
                        }else if ("1".equals(type)){
                            Intent intent = new Intent();
                            intent.setClass(ChatActivity.this, CommodityListActivity.class);
                            intent.putExtra("shopId",merchant.getShopId());
                            intent.putExtra("shopName",merchant.getShopName());
                            startActivity(intent);
                        }

                    } else {//失败
                        TipUtil.showToast(message, ChatActivity.this, 1);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(getResources().getString(R.string.error_service),ChatActivity.this, 1);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(getResources().getString(R.string.error_network), ChatActivity.this, 1);
                TipUtil.closeProgressDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
//                SharedPreferences mainSharedPreferences =getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
//                String userId = mainSharedPreferences.getString("userId", "");
//                map.put("loginId", userId);
                map.put("shopId",shopId);
                return map;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences = getSharedPreferences(com.century.sjt.util.Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);
    }
    //翻译查询

    private void transInfoDetail(final String type) {
        TipUtil.openProgressDialog(com.century.sjt.util.Constant.APPLICATION_NAME, getResources().getString(R.string.error_please_waitting), ChatActivity.this);
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.transInfo, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TipUtil.closeProgressDialog();
                    TipUtil.log("接口返回成功", response.toString(), 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("200")) {//成功
                        JSONObject aData = res.getJSONObject("data");
                        String hasTransService = aData.getString("hasTransService");
                        if ("1".equals(hasTransService)){
                            SharedPreferences.Editor editor = mainSharedPreferences.edit();
                            editor.putString("isTrans", hasTransService);
                            editor.commit();
                        }else {
                            //询问是否取消
                            AlertDialog.Builder builder = new AlertDialog.Builder(ChatActivity.this);
                            builder.setMessage(getResources().getString(R.string.text_noopen_translate));
                            builder.setPositiveButton(getResources().getString(R.string.btn_yes), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    if ("1".equals(type)){
                                        startActivity(ChatActivity.this, TranslateShopActivity.class);
                                    }else {
                                        startActivity(ChatActivity.this, TranslateActivity.class);
                                    }

                                }
                            });
                            builder.setNegativeButton(getResources().getString(R.string.btn_no), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                            builder.setCancelable(false);
                            builder.create().show();
                        }

                    } else {//失败
                        TipUtil.showToast(message, ChatActivity.this, 1);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(getResources().getString(R.string.error_service),ChatActivity.this, 1);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(getResources().getString(R.string.error_network), ChatActivity.this, 1);
                TipUtil.closeProgressDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                SharedPreferences mainSharedPreferences =getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String userId = mainSharedPreferences.getString("userId", "");
                map.put("loginId", userId);
                return map;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences = getSharedPreferences(com.century.sjt.util.Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);
    }

    public void isOpenBaiduTranslate(final String operate){
        StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.setAutoTrans, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                try {
                    TipUtil.closeProgressDialog();
                    TipUtil.log("接口返回成功", response.toString(), 1);
                    JSONTokener jsonParser = new JSONTokener(response);
                    JSONObject res = (JSONObject) jsonParser.nextValue();
                    String code = res.getString("code");
                    String message = res.getString("message");
                    if (code.equals("200")) {//成功

                    } else {//失败
                        TipUtil.showToast(message, ChatActivity.this, 1);
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    TipUtil.showToast(getResources().getString(R.string.error_service),ChatActivity.this, 1);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                TipUtil.showToast(getResources().getString(R.string.error_network), ChatActivity.this, 1);
                TipUtil.closeProgressDialog();
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<String, String>();
                SharedPreferences mainSharedPreferences =getSharedPreferences(Constant.TAG, Activity.MODE_PRIVATE);
                String userId = mainSharedPreferences.getString("userId", "");
                map.put("loginId", userId);
                map.put("operate",operate);//0 关闭 1 开启
                return map;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                SharedPreferences mainSharedPreferences = getSharedPreferences(com.century.sjt.util.Constant.TAG, Activity.MODE_PRIVATE);
                String cookie = mainSharedPreferences.getString("cookie", "");
                String rememberMeValue = mainSharedPreferences.getString("rememberMe", "");
                HashMap localHashMap = new HashMap();
                String cookieValue = cookie + ";" + rememberMeValue;
                localHashMap.put("Cookie", cookieValue);
                return localHashMap;
            }
        };
        mQueue.add(stringRequest);
    }
}
